﻿using System;
using System.ComponentModel;
using Kingdee.BOS.Core.Bill.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Util;

namespace ZKHY.BUSSINESS.PLUGIN
{
	// Token: 0x02000002 RID: 2
	[HotUpdate]
	[Description("差旅费报销 表单插件2")]
	public class CLFBEditV2 : AbstractBillPlugIn
	{
		// Token: 0x06000001 RID: 1 RVA: 0x00002050 File Offset: 0x00000250
		public override void AfterCreateNewEntryRow(CreateNewEntryEventArgs e)
		{
			base.AfterCreateNewEntryRow(e);
			bool flag = StringUtils.EqualsIgnoreCase(e.Entity.Key, "FEntity");
			if (flag)
			{
				int num = Convert.ToInt32(base.View.Model.GetValue("FTravelSeq", e.Row));
				object value = base.View.Model.GetValue("F_UNW_KSSJ", num - 1);
				DateTime dateTime;
				bool flag2;
				if (value is DateTime)
				{
					dateTime = (DateTime)value;
					flag2 = true;
				}
				else
				{
					flag2 = false;
				}
				bool flag3 = flag2;
				if (flag3)
				{
					base.View.Model.SetValue("F_BDI_KSSJ", dateTime, e.Row);
				}
				value = base.View.Model.GetValue("F_UNW_JSSJ", num - 1);
				DateTime dateTime2;
				bool flag4;
				if (value is DateTime)
				{
					dateTime2 = (DateTime)value;
					flag4 = true;
				}
				else
				{
					flag4 = false;
				}
				bool flag5 = flag4;
				if (flag5)
				{
					base.View.Model.SetValue("F_BDI_JSSJ", dateTime2, e.Row);
				}
				decimal num2 = Convert.ToDecimal(base.View.Model.GetValue("F_UNW_FGZSJCCTS", num - 1));
				decimal num3 = Convert.ToDecimal(base.View.Model.GetValue("F_UNW_SC", num - 1));
				base.View.Model.SetValue("F_UNW_FGZSJ", num2, e.Row);
				base.View.Model.SetValue("F_BDI_SC", num3, e.Row);
			}
		}

		// Token: 0x06000002 RID: 2 RVA: 0x000021DC File Offset: 0x000003DC
		public override void DataChanged(DataChangedEventArgs e)
		{
			base.DataChanged(e);
			string key = e.Field.Key;
			bool flag = key.Equals("F_UNW_JSSJ") || key.Equals("F_UNW_KSSJ");
			if (flag)
			{
				object value = base.View.Model.GetValue("F_UNW_KSSJ", e.Row);
				DateTime dateTime;
				bool flag2;
				if (value is DateTime)
				{
					dateTime = (DateTime)value;
					flag2 = true;
				}
				else
				{
					flag2 = false;
				}
				bool flag3 = flag2;
				if (flag3)
				{
					value = base.View.Model.GetValue("F_UNW_JSSJ", e.Row);
					DateTime dateTime2;
					bool flag4;
					if (value is DateTime)
					{
						dateTime2 = (DateTime)value;
						flag4 = true;
					}
					else
					{
						flag4 = false;
					}
					bool flag5 = flag4;
					if (flag5)
					{
						double num = 0.0;
						bool flag6 = dateTime.Hour < 17;
						if (flag6)
						{
							num += 1.0;
						}
						bool flag7 = dateTime.Date == dateTime2.Date;
						if (!flag7)
						{
							bool flag8 = dateTime.Date.AddDays(1.0) == dateTime2.Date;
							if (flag8)
							{
								bool flag9 = dateTime.Hour >= 17;
								if (flag9)
								{
									num = 1.0;
								}
								else
								{
									DateTime t = new DateTime(dateTime2.Year, dateTime2.Month, dateTime2.Day, 8, 30, 0);
									DateTime t2 = new DateTime(dateTime2.Year, dateTime2.Month, dateTime2.Day, 12, 30, 0);
									bool flag10 = dateTime2 >= t;
									if (flag10)
									{
										bool flag11 = dateTime2 < t2;
										if (flag11)
										{
											num += 0.5;
										}
										else
										{
											num += 1.0;
										}
									}
								}
							}
							else
							{
								DateTime t3 = new DateTime(dateTime2.Year, dateTime2.Month, dateTime2.Day, 12, 30, 0);
								DateTime t4 = new DateTime(dateTime2.Year, dateTime2.Month, dateTime2.Day, 8, 30, 0);
								bool flag12 = dateTime2 >= t4;
								if (flag12)
								{
									bool flag13 = dateTime2 < t3;
									if (flag13)
									{
										num += 0.5;
									}
									else
									{
										num += 1.0;
									}
								}
								num += (double)((dateTime2.Date - dateTime.Date).Days - 1);
							}
						}
						base.View.Model.SetValue("F_UNW_SC", num, e.Row);
						int entryRowCount = base.View.Model.GetEntryRowCount("FEntity");
						for (int i = 0; i < entryRowCount; i++)
						{
							int num2 = Convert.ToInt32(base.View.Model.GetValue("FTravelSeq", i));
							bool flag14 = num2 == e.Row + 1;
							if (flag14)
							{
								base.View.Model.SetValue("F_BDI_KSSJ", dateTime, i);
								base.View.Model.SetValue("F_BDI_JSSJ", dateTime2, i);
								base.View.Model.SetValue("F_BDI_SC", num, i);
							}
						}
					}
				}
			}
			bool flag15 = key.Equals("F_UNW_FGZSJCCTS");
			if (flag15)
			{
				int entryRowCount2 = base.View.Model.GetEntryRowCount("FEntity");
				for (int j = 0; j < entryRowCount2; j++)
				{
					int num3 = Convert.ToInt32(base.View.Model.GetValue("FTravelSeq", j));
					bool flag16 = num3 == e.Row + 1;
					if (flag16)
					{
						base.View.Model.SetValue("F_UNW_FGZSJ", e.NewValue, j);
					}
				}
			}
			bool flag17 = key.Equals("F_BDI_KSSJ") || key.Equals("F_BDI_JSSJ");
			if (flag17)
			{
				object value = base.View.Model.GetValue("F_BDI_KSSJ", e.Row);
				DateTime dateTime3;
				bool flag18;
				if (value is DateTime)
				{
					dateTime3 = (DateTime)value;
					flag18 = true;
				}
				else
				{
					flag18 = false;
				}
				bool flag19 = flag18;
				if (flag19)
				{
					value = base.View.Model.GetValue("F_BDI_JSSJ", e.Row);
					DateTime t5;
					bool flag20;
					if (value is DateTime)
					{
						t5 = (DateTime)value;
						flag20 = true;
					}
					else
					{
						flag20 = false;
					}
					bool flag21 = flag20;
					if (flag21)
					{
						double num4 = 0.0;
						bool flag22 = dateTime3.Hour < 17;
						if (flag22)
						{
							num4 += 1.0;
						}
						bool flag23 = dateTime3.Date == t5.Date;
						if (!flag23)
						{
							bool flag24 = dateTime3.Date.AddDays(1.0) == t5.Date;
							if (flag24)
							{
								bool flag25 = dateTime3.Hour >= 17;
								if (flag25)
								{
									num4 = 1.0;
								}
								else
								{
									DateTime t6 = new DateTime(t5.Year, t5.Month, t5.Day, 8, 30, 0);
									DateTime t7 = new DateTime(t5.Year, t5.Month, t5.Day, 12, 30, 0);
									bool flag26 = t5 >= t6;
									if (flag26)
									{
										bool flag27 = t5 < t7;
										if (flag27)
										{
											num4 += 0.5;
										}
										else
										{
											num4 += 1.0;
										}
									}
								}
							}
							else
							{
								DateTime t8 = new DateTime(t5.Year, t5.Month, t5.Day, 12, 30, 0);
								DateTime t9 = new DateTime(t5.Year, t5.Month, t5.Day, 8, 30, 0);
								bool flag28 = t5 >= t9;
								if (flag28)
								{
									bool flag29 = t5 < t8;
									if (flag29)
									{
										num4 += 0.5;
									}
									else
									{
										num4 += 1.0;
									}
								}
								num4 += (double)((t5.Date - dateTime3.Date).Days - 1);
							}
						}
						base.View.Model.SetValue("F_BDI_SC", num4, e.Row);
					}
				}
			}
		}
	}
}
